****
* Decomposition
***

clear 

grstyle init
 grstyle set plain, horizontal grid dotted


*** load relevant data
 

		
		use "$Replicationdirectory/_Work/TEMP/_data_bonds"
		
		merge m:1 date     using "$Replicationdirectory/_Work/TEMP/CONSOL_DAILY_LONDON.dta"
		
			keep if _merge==3	
			drop   _merge
			
			
				
			gen Consol_british=100*(2.5/Consol_London_GBP)	 
		
 
  		 
		
			 *** load  liquidity premia
		 
		 merge 1:1 date using "$Replicationdirectory/_Work/TEMP/LQP"
		 
		 
				 * (this drops weekends)
				 drop if _merge!=3
				 
				 drop _merge 
				 
				    
		
		**** Senior/general German default risk 
		
		gen baseline_default_risk=ytm_london_lastavail-(Consol_british)-LP_OVER_Cons_london
 		  

		**** calculate spreads for markets
		
			foreach x of global markets{
 			gen spread_`x'_london=ytm_`x'_lastavail-ytm_london_lastavail
  			}
						
			
		*** summary stats 
		
		sum Consol_british  if default==1
		sum baseline_default_risk  if default==1
		
 		sum spread_paris_london if default==1
		sum spread_zurich_london if default==1
		sum spread_amsterdam_london if default==1
		
		sum ytm_paris_lastavail 	 if default==1	
		sum ytm_amsterdam_lastavail 	 if default==1	
		sum ytm_zurich_lastavail 	 if default==1	
		
		
		gen  s_DR_Paris=spread_paris_london/ytm_paris  if default==1	
		sum s_DR_Paris
		gen  s_DR_zurichs=spread_zurich_london/ytm_zurich  if default==1	
		sum s_DR_zurichs
		gen  s_DR_AMS=spread_amsterdam_london/ytm_amsterdam  if default==1	
		sum s_DR_AMS
		
		save  "$Replicationdirectory/_Work/TEMP/spreads_dta_ytm", replace
				
				
		*** calculate selective default risk // Differentiate between liquidity premia and selective default risk  in spread over London [ (psi_j-psi_s) is already  defined as: LP_OVER_SeniorDawes_`market'  but missings should be set to 0 pre default ]
		
		foreach x of global markets{
			
				replace LP_OVER_SeniorDawes_`x'= 0 if LP_OVER_SeniorDawes_`x'==.
				
				gen SD_risk_premium_`x'=spread_`x'_london-LP_OVER_SeniorDawes_`x'
				
		}
		
		
				 
				 
				 
	
	
		*** set transaction costs 
		
	 	foreach x of global markets{
 		
		gen transactioncost_`x'=SD_risk_premium_`x'	if tin(1jan1930,14jun1934)
		replace transactioncost_`x'=0 if tin(14jun1934,1jan1940)
		replace SD_risk_premium_`x'=0 if tin(1jan1930,14jun1934)
		
		}		 
		
		
		**** define liquidity premia for seniior market 
		
		* psi_s (senior Dawes over risk-free asset)
			gen LP_senior=LP_OVER_Cons_london
		
	
		
		 
		
		**** define sample
		keep if tin(1jan1930,1aug1939)
			 
 				 
	**** Decomposition 7% 
							foreach x of global markets{
							gen safe_rate_risk_`x'=(Consol_british)
							gen incl_lqprelC_`x'=safe_rate_risk_`x'+LP_OVER_Cons_london
							gen incl_baseline_risk_`x'= safe_rate_risk_`x'+LP_OVER_Cons_london+baseline_default_risk
							*gen incl_spread_premium_`x'=incl_baseline_risk_`x'+(spread_`x'_london-liqu)			
							gen incl_spread_premium_`x'= incl_baseline_risk_`x'+SD_risk_premium_`x'
							gen incl_DAWES_LIQ_`x'=incl_spread_premium_`x'+LP_OVER_SeniorDawes_`x'
							gen incl_transactioncost_`x'=incl_DAWES_LIQ_`x' +transactioncost_`x'		
 							 
							 
									}				
					
					
				 
				
				*** improve visibility of layers ( there is no liq premium of junior Dawes over senior Dawes before June 1934 but area graph makes it look like it )
				replace incl_DAWES_LIQ_paris=0 if default==0
				replace incl_DAWES_LIQ_amsterdam=0 if default==0
				replace incl_DAWES_LIQ_zurich=0 if default==0
				

				replace incl_transactioncost_london=0			 
				replace incl_transactioncost_paris=0			if default==1
				replace incl_transactioncost_amsterdam=0		if default==1
				replace incl_transactioncost_zurich=0			if default==1
				
					
					
					
					
 				
 
 
				  
 				* London
 				
				twoway ///
				(area  incl_transactioncost_london incl_baseline_risk_london incl_lqprelC_london safe_rate_risk_london      date   	,    ///
				ytitle("") xtitle("") ysize(8)  ylabel(0(10)40, labsize(small)) yscale(range(10 40)) fintensity(inten100   inten50     inten100 inten50) ///
				fcolor(   magenta  blue green gold  ) lcolor(   magenta  blue green gold  ) lwidth(.0   .0 .0  .0  .0  )  ///
				legend(order(4 "Risk-free rate" 3 "Liquidity premium ({&psi}{sub:s})" 2 "General default risk"  1 "Arbitrage Cost" ) region(lcolor(none) ))) ///
				 (scatteri 40 `=d(14jun1934)' 0 `=d(14jun1934)', recast(line) lp(solid) lc(black) )  ///
				 (scatteri 40  `=d(28jun1938)' 0 `=d(28jun1938)', recast(line) lp(dash) lc(black) )  ///
				, title("{stMono:London} ",size(mediumsmal) color(black)) saving("$Replicationdirectory/_Work/TEMP/7percent_london", replace)    bgcolor(white)  graphregion(color(white))  bgcolor(white)  bgcolor(white)  tline(14jun1934, lp(solid) lc(black)  ) ///
				tlabel(01jan1930 "1930" 01jan1931 "1931" 01jan1932 "1932" 01jan1933 "1933" 01jan1934 "1934" 01jan1935 "1935" 01jan1936 "1936" 01jan1937 "1937" 01jan1938 "1938" 01jan1939 "1939" ,angle(45) labsize(small) )  ///
				xtitle("")  plotr(m(zero))
				
				
				
				*Paris
				twoway (area  incl_transactioncost_paris incl_DAWES_LIQ_paris incl_spread_premium_paris   incl_baseline_risk_london incl_lqprelC_london safe_rate_risk_london       date  	,    /// 
				ytitle("") xtitle("") ysize(8) ylabel(0(10)40, labsize(small)) yscale(range(10 40)) fintensity(inten100 inten100 inten50   inten50 inten100 inten100) fcolor( magenta maroon  red blue green   gold  ) ///
				lcolor(   magenta	maroon red blue green   gold  )  lwidth(.2 .2 .0 .0 .4 .0  )  legend(size(tiny) order(7 "Market segmentation" 8 "Coupon change"  6 "Risk-free rate (r)" 5 "Liquidity premium ({&psi}{sub:s})" 4 "General default risk ({&theta}(1-{&pi}))" 3 "Selective default risk ({&theta}{&pi})" 2 "Liquidity premium ({&psi}{sub:j}-{&psi}{sub:s})" 1 "Arbitrage cost") ///
				region(color(white) lcolor(white)  )   c(3) ring(1) pos(6) ) ) ///
				(scatteri 40 `=d(14jun1934)' 0 `=d(14jun1934)', recast(line) lp(solid) lc(black) )  ///
				(scatteri 40  `=d(5jul1938)' 0 `=d(5jul1938)', recast(line) lp(dash) lc(black) )  ///
				, title("{stMono:Paris} ",size(mediumsmall) color(black)) saving("$Replicationdirectory/_Work/TEMP/7percent_paris", replace)  ///
				bgcolor(white)  graphregion(color(white))  bgcolor(white)  bgcolor(white)  tline(14jun1934, lp(solid) lc(black)  ) ///
				tlabel(01jan1930 "1930" 01jan1931 "1931" 01jan1932 "1932" 01jan1933 "1933" 01jan1934 "1934" 01jan1935 "1935" 01jan1936 "1936" 01jan1937 "1937" 01jan1938 "1938" 01jan1939 "1939" ,angle(45) labsize(small) )     xtitle("") plotr(m(zero))
				
				
				
				* Amsterdam
  				twoway (area  incl_transactioncost_amsterdam incl_DAWES_LIQ_amsterdam incl_spread_premium_amsterdam   incl_baseline_risk_london incl_lqprelC_london safe_rate_risk_london       date  	, ///
				  ytitle("") xtitle("") ysize(8)  ylabel(0(10)40, ///
				labsize(small)) yscale(range(10 40)) fintensity(inten100 inten100 inten50   inten50 inten100 inten100) ///
				fcolor( magenta maroon  red blue green   gold  ) lcolor(   magenta	maroon red blue green   gold  ) lwidth(.2 .2 .0 .0 .4 .0  ) ///
				legend(size(vsmall) order(6 "Risk-free rate" 5 "Liquidity premium ({&psi}{sub:s}-{&psi}{sub:RF})" 4 "General default risk" 3 "Selective default risk" 2 "Liquidity premium ({&psi}{sub:j})" 1 "Transaction cost (arbitrage)") ///
				region(lcolor(white) lwidth(none))   c(1))) ///
				(scatteri 40 `=d(14jun1934)' 0 `=d(14jun1934)', recast(line) lp(solid) lc(black) )  ///
				(scatteri 40  `=d(14jun1935)' 0 `=d(14jun1935)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(1jun1937)' 0 `=d(1jun1937)', recast(line) lp(dash) lc(black) )  ///
				, title("{stMono:Amsterdam} ",size(mediumsmall) color(black)) saving("$Replicationdirectory/_Work/TEMP/7percent_amsterdam", replace)  ///
				bgcolor(white)  graphregion(color(white))  bgcolor(white)  bgcolor(white)  tline(14jun1934, lp(solid) lc(black)  ) ///
				tlabel(01jan1930 "1930" 01jan1931 "1931" 01jan1932 "1932" 01jan1933 "1933" 01jan1934 "1934" 01jan1935 "1935" 01jan1936 "1936" 01jan1937 "1937" 01jan1938 "1938" 01jan1939 "1939" ,angle(45) labsize(small) )  ///
				xtitle("") plotr(m(zero))

 				
				* Zurich
				twoway (area  incl_transactioncost_zurich incl_DAWES_LIQ_zurich incl_spread_premium_zurich   incl_baseline_risk_london incl_lqprelC_london safe_rate_risk_london       date  				, ///
 				ytitle("") xtitle("") ysize(8) ylabel(0(10)40, labsize(small)) yscale(range(10 40)) fintensity(inten100 inten100 inten50   inten50 inten100 inten100)  fcolor( magenta maroon  red blue green   gold  ) ///
				lcolor(   magenta	maroon red blue green   gold)   lwidth(.2 .2 .0 .0 .4 .0  )    legend(size(vsmall) order(6 "Risk-free rate" 5 "Liquidity premium ({&psi}{sub:s}-{&psi}{sub:RF})" 4 "General default risk" 3 "Selective default risk" 2 "Liquidity premium ({&psi}{sub:j})" 1 "Transaction cost (arbitrage)") ///
				region(lcolor(white) lwidth(none))   c(1)))  		///
				(scatteri 40 `=d(14jun1934)' 0 `=d(14jun1934)', recast(line) lp(solid) lc(black) )  ///
				(scatteri 40  `=d(17apr1935)' 0 `=d(17apr1935)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(6jul1936)' 0 `=d(6jul1936)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(18oct1936)' 0 `=d(18oct1936)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(23dec1936)' 0 `=d(23dec1936)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(30jun1937)' 0 `=d(30jun1937)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(30june1938)' 0 `=d(30june1938)', recast(line) lp(dash) lc(black) )  ///
				(scatteri 40  `=d(5Jul1939)' 0 `=d(5Jul1939)', recast(line) lp(dash) lc(black) )  ///	
				, title("{stMono:Zurich} ",size(mediumsmall) color(black)) saving("$Replicationdirectory/_Work/TEMP/7percent_zurich", replace)    bgcolor(white)  graphregion(color(white))  bgcolor(white) ///
				bgcolor(white)  tline(14jun1934, lp(dash) lc(black)  ) tlabel(01jan1930 "1930" 01jan1931 "1931" 01jan1932 "1932" 01jan1933 "1933" 01jan1934 "1934" 01jan1935 "1935" 01jan1936 "1936" 01jan1937 "1937" 01jan1938 "1938" 01jan1939 "1939" ,angle(45) labsize(small) )  ///
				xtitle("") plotr(m(zero))
		
				 
				
				
				grc1leg2   "$Replicationdirectory/_Work/TEMP/7percent_london"    "$Replicationdirectory/_Work/TEMP/7percent_paris"   "$Replicationdirectory/_Work/TEMP/7percent_amsterdam"    "$Replicationdirectory/_Work/TEMP/7percent_zurich",  						 l1("{stMono: Yield-to-maturity(%)} "  )		legendfrom("$Replicationdirectory/_Work/TEMP/7percent_paris")   graphregion(color(white) )   
				
				graph display  , ysize(18) xsize(16.0)
			
				
 
				graph export "$Replicationdirectory/_Work/Output/Figures/Figure4_Decomposition.pdf", replace

				    
				
				   
 	
			
			*** descriptives 
			 
			
				*** average risk spreads 
				
				sum safe_rate_risk_* if default==1
				
				sum baseline_default_risk if default==1
				
				sum SD_risk_premium_paris			if default==1
				sum SD_risk_premium_amsterdam			if default==1
				sum SD_risk_premium_zurich			if default==1
				
				 
			
				 
				
				
				*** average yield
				
				sum ytm_paris_lastavail  if default==1
				sum ytm_amsterdam_lastavail  if default==1
				sum ytm_zurich_lastavail  if default==1
				
				
				 
				 
										
				 
			